<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />

    <style type="text/css">
        .class-title {
            margin-top: 10px;
            margin-left: 10px;
            margin-right: 10px;
            font-size: 20px;
            font-weight: bold;
            color: #00BFFF;
        }

        .class-hr {
            margin-top: 5px;
            height: 1px;
            border: none;
            border-top: 1px solid #DCDCDC;
        }

        .class-seqno {
            margin-top: 3px;
            margin-left: 10px;
            margin-right: 25px;
            font-size: 10px;
            color: #808080;
            font-weight: bold;
            text-align: right;
        }

        .class-table {
            width: 100%;
            text-align: left;
            color: black;
            font-size: 13px;
            margin-left: 2%;
            width: 100%;
            table-layout: fixed;
        }

        .class-td {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:60px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">检测单</div>
                    <div class="aui-list-item-input">
                        <input type="text" placeholder="选择检测单" id="chkBillCode" readonly="true" onclick="goSelectChkBill()" />
                    </div>
                    <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectChkBill()"></i>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">检测类型</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="chkTypeName" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">物料号</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="mrlCode" disabled="true">
                    </div>
                </div>
            </li>
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label">物料名</div>
                    <div class="aui-list-item-input">
                        <input type="text" id="mrlName" disabled="true">
                    </div>
                </div>
            </li>
        </ul>
    </div>

    <div class='aui-btn aui-btn-info aui-btn-block' style="margin-top:10px;" onclick='closeChkBill()'>进入检测单关闭界面</div>

    <div id="divhtml" style="display: block;width:100%;overflow-y: scroll;margin-top:10px;"></div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    var chkBillType = ""; //检测单类型
    apiready = function() {
        var query = api.pageParam.query;
        chkBillType = query.chkBillType;
        title = query.title;
        document.getElementById("title").innerHTML = title;
    };

    //选择检测单
    function goSelectChkBill() {
        api.openWin({
            name: 'qcmSelectChkBill',
            url: 'qcmSelectChkBill.html',
            pageParam: {
                processState: "0", //审核状态：0未处理，3处理中，7已处理，8已确认，9已取消
                chkBillType: chkBillType,
                name: "qcmChkBillac",
            }
        });
    }

    //检测单选择后回调函数
    function setChkBill(id, code, mrlCode, mrlName, opCode, opName, chkTypeName) {
        $("#chkBillCode").val(code);
        $("#mrlCode").val(mrlCode);
        $("#mrlName").val(mrlName);
        $("#chkTypeName").val(chkTypeName);

        //查询检测明细
        doSearchChkBillDetails();
    }

    //查询检测单明细项
    function doSearchChkBillDetails() {

        //检测单号
        var chkBillCode = $("#chkBillCode").val();

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getChkBillDetails";
        var data = {
            values: {
                chkBillCode: chkBillCode,
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                if (myobj.code == '0') {
                    var list = eval(myobj.list);

                    createTable(list);

                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    $api.html($api.byId("divhtml"), "");
                }
            }
        });
    }

    //构造表格数据
    function createTable(list) {
        var html = "";
        //遍历
        for (var i = 0; i < list.length; i++) {
            // 序号
            html += "<div class='class-seqno'>";
            html += "<span>" + (i + 1) + "</span>";
            html += "</div>";
            //表格
            html += "<div style='margin-left:10px;margin-right:15px;'>";
            html += "<table class='class-table'>";
            html += "<tr>";
            html += "<td class='class-td' colspan = '2'>物料编码:    " + list[i].mrlCode + "</td>";
            html += "</tr>";
            html += "<tr>";
            html += "<td class='class-td' colspan = '2'>物料名称:    " + list[i].mrlName + "</td>";
            html += "</tr>";
            html += "<tr>";
            html += "<td class='class-td' colspan = '2'>序  列  号:    " + list[i].serialNo + "</td>";
            html += "</tr>";
            html += "<tr>";
            html += "<tr>";
            html += "<td class='class-td' style='width:50%'>批  次  号:    " + list[i].lotCode + "</td>";
            html += "<td class='class-td' style='width:50%'>检测数量:    " + list[i].qty + "</td>";
            html += "</tr>";
            html += "<td class='class-td'>工序编码:    " + list[i].opCode + "</td>";
            html += "<td class='class-td'>工序名称:    " + list[i].opName + "</td>";
            html += "</tr>";
            html += "<tr>";
            html += "<td class='class-td'>工  单  号:    " + list[i].workOrderCode + "</td>";
            if (list[i].chkResult == "未判定") {
                html += "<td class='class-td' style='color:red;'>处理结果:    " + list[i].chkResult + "</td>";
            } else {
                html += "<td class='class-td' style='color:green;'>处理结果:    " + list[i].chkResult + "</td>";
            }
            html += "</tr>";
            html += "<tr>";
            html += "<td class='class-td'>";
            html += "<div class='aui-btn aui-btn-info' onclick='deal(\"" + list[i].chkBillDetailsId + "\")'>";
            html += "处理</div></td>";
            html += "</tr>";
            html += "</table>";
            html += "<hr class='class-hr' />";
            html += "</div>";
        }

        $api.html($api.byId("divhtml"), html);
    }

    //处理
    function deal(chkBillDetailsId) {
        var chkBillCode = $("#chkBillCode").val();

        api.openWin({
            name: 'qcmChkBillDeal',
            url: 'qcmChkBillDeal.html',
            pageParam: {
                chkBillDetailsId: chkBillDetailsId,
                chkBillCode: chkBillCode,
                name: "qcmChkBillac",
            }
        });
    }

    //进入检测单关闭界面
    function closeChkBill() {
        var chkBillCode = $("#chkBillCode").val();

        if (chkBillCode == null || chkBillCode == "" || chkBillCode == undefined) {
            api.toast({
                msg: "请选择检测单",
                duration: 3000
            });
            return;
        }

        api.openWin({
            name: 'qcmChkBillClose',
            url: 'qcmChkBillClose.html',
            pageParam: {
                chkBillCode: chkBillCode,
                name: "qcmChkBillac",
            }
        });
    }

    //清空
    function reset() {
        $api.html($api.byId("divhtml"), "");
        $("#chkBillCode").val("");
        $("#mrlCode").val("");
        $("#mrlName").val("");
        $("#chkTypeName").val("");
    }

    //返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>
